home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  4.6 KB  |  146 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * macros.h ---    macro definitions for the portable forth environment
  31.  * (duz 09May93)
  32.  */
  33.  
  34. #ifndef __MACROS_H
  35. #define __MACROS_H
  36.  
  37. #ifndef __CONFIG_H
  38. #include "config.h"
  39. #endif
  40.  
  41. #ifndef __CONST_H
  42. #include "const.h"
  43. #endif
  44.  
  45. #ifndef CHAR_BIT
  46. #include <limits.h>
  47. #endif
  48.  
  49. /* determines the dimension of any given vector */
  50. #define DIM(X)        ((int)(sizeof (X) / sizeof *(X)))
  51. /* wipe any given vector X */
  52. #define ZERO(X)        (memset ((X), 0, sizeof (X)))
  53. /* copy any given vector Y to X */
  54. #define COPY(X,Y)    (memcpy ((X), (Y), sizeof (X)))
  55. /* return the byte offset of a given component to beginning of structure: */
  56. #define OFFSET_OF(T,C)    ((char *)&(((T *)0)->C) - (char *)0)
  57.  
  58. /* inc/decrement, push/pop of arbitrary types with arbitrary pointers */
  59. #if defined __GNUC__ && !defined __STRICT_ANSI__ && !defined __cplusplus
  60. /* Use non-ANSI extensions avoiding address-of operator: */
  61. #define INC(P,T)    (((T *)(P))++)
  62. #define DEC(P,T)    (--((T *)(P)))
  63. #define ADD(P,N)    ((char *)(P) += (N))
  64. #elif defined MSDOS
  65. #define INC(P,T)    (((T *huge)(P))++)
  66. #define DEC(P,T)    (--((T *huge)(P)))
  67. #define ADD(P,N)    ((char *huge)(P) += (int)(N))
  68. #else
  69. /* Force (or fool) ANSI-C to do typecast's it normally refuses by */
  70. /* casting pointers, not objects, then reference the casted pointers: */
  71. #define INC(P,T)    ((*(T **)&(P))++)
  72. #define DEC(P,T)    (--(*(T **)&(P)))
  73. #define ADD(P,N)    (*(char **)&(P) += (N))
  74. #endif
  75.  
  76. #define POP(T,P,X)    ((X) = *INC (P, T))
  77. #define PUSH(T,X,P)    (*DEC (P, T) = (X))
  78.  
  79. /* useful shortcuts */
  80.  
  81. #ifdef OLDCPP
  82. #define STRING(X)    "X"
  83. #define APPEND(X,Y)    X/**/Y
  84. #else
  85. #define STRING(X)    #X
  86. #define APPEND(X,Y)    X##Y
  87. #endif
  88. #define STRING1(X)    STRING(X)
  89.  
  90. #define code(X)        void APPEND(X,_) (void)    /* declare a primitive */
  91. #define Code(X)        static code (X)        /* declare a local primitive */
  92.  
  93. #define NFA        (to_name (W))
  94. #define CFA        (W)
  95. #define PFA        ((Cell *)&W [1])
  96.  
  97. #define    FLAG(X)        ((X) ? TRUE : FALSE)
  98.  
  99. #define BITSOF(X)    ((int)(sizeof (X) * CHAR_BIT))
  100. #define CELLBITS    BITSOF (Cell)
  101. #define HALFCELL    (BITSOF (Cell) >> 1)
  102. #define HIGHBIT(X)    ((X) >> (BITSOF (X) - 1))
  103.  
  104. #define CELL_MAX    ((Cell)((uCell)-1 >> 1))
  105. #define UCELL_MAX    ((uCell)-1)
  106.  
  107. #define RP        ((Cell *)rp)
  108. #define RPUSH(X)    PUSH (Cell, X, rp)
  109. #define RPOP(X)        POP (Cell, rp, X)
  110. #if 0
  111. #define    BRANCH        ADD (ip, *(Cell *)ip)
  112. #else
  113. #define    BRANCH        (ip = (Xt*)*ip)
  114. #endif
  115. #define SKIP_STRING    ADD (ip, aligned (*(Byte *)ip + 1))
  116. #define ALIGNED(P)    (((size_t)(P) & (CELL_ALIGN - 1)) == 0)
  117. #define DFALIGNED(P)    (((size_t)(P) & (DFLOAT_ALIGN - 1)) == 0)
  118. #define SFALIGNED(P)    (((size_t)(P) & (SFLOAT_ALIGN - 1)) == 0)
  119.  
  120. #define PAD        ((char *)DP + MIN_HOLD)
  121. #define    DEPTH        (memtop.stk - sp)
  122. #define    COMMA(X)    (*(Cell *)DP = (Cell)(X), INC (DP, Cell))
  123. #define FCOMMA(F)    (*(double *)DP = (F), INC (DP, double))
  124.  
  125. #define UDDOTR(UD,W,BUF) outs (str_ud_dot_r (UD, &(BUF)[sizeof (BUF)], W,BASE))
  126. #define DDOTR(D,W,BUF)    outs (str_d_dot_r (D, &(BUF) [sizeof (BUF)], W, BASE))
  127. #define DOT(N,BUF)    outs (str_dot (N, &(BUF) [sizeof (BUF)], BASE))
  128.  
  129. /* long <-> dCell conversion macros, won't work on 16 bit machines */
  130. #define UL2UDC(UL, UDC)    ((UDC).hi = 0, (UDC).lo = (uCell)(UL))
  131. #define UDC2UL(HI, LO)    (LO)
  132.  
  133. /* Given a Cell or dCell these macros access the half cell components of it: */
  134. /* (yes yes this is non ANSI C but it works) */
  135. #define    W0(X)        (((Cell_map *)&(X))->hi)
  136. #define    W1(X)        (((Cell_map *)&(X))->lo)
  137.  
  138. #define    D0(X)        W0((X).hi)
  139. #define    D1(X)        W1((X).hi)
  140. #define    D2(X)        W0((X).lo)
  141. #define    D3(X)        W1((X).lo)
  142.  
  143. #define CELL(HI,LO)    ((Cell)(HI) << HALFCELL | (LO))
  144.  
  145. #endif /* __MACROS_H */
  146.